﻿#region Author

//// Yevhen Bobrov, http://blog.xtalion.com 

#endregion

using System;
using System.Linq.Expressions;
using System.Windows.Input;

namespace Silverlight.Core.Infrastructure
{
	public class ViewModelCommandBuilder
	{
		readonly ViewModelBase _viewModel;

		public ViewModelCommandBuilder(ViewModelBase viewModel)
		{
			_viewModel = viewModel;
		}

		public ICommand For(Expression<Action> expression)
		{
			var methodCall = (MethodCallExpression)expression.Body;

			return new ViewModelCommand(_viewModel, methodCall.Method, 
										_viewModel.GetType().GetProperty("Can" + methodCall.Method.Name));
		}
	}
}